package com.prs.crm.action.person;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.person.Department;
import com.prs.crm.domain.person.Dossier;
import com.prs.crm.domain.person.PostChange;
import com.prs.crm.domain.person.PostSet;
import com.prs.crm.service.person.DepartmentService;
import com.prs.crm.service.person.DossierService;
import com.prs.crm.service.person.PostChangeService;
import com.prs.crm.service.person.PostSetService;

public class PostChangeAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private Integer[] ids;
	private PaginationSupport pagination;
	private PostChange postChange;
	private PostChangeService postChangeService;
	private Dossier dossier;
	private DossierService dossierService;
	private Integer dossierId;
	
	private List<Department> department;
	private DepartmentService departmentService;
	
	private List<PostSet> postSet;
	private PostSetService postSetService;

	public List<Department> getDepartment() {
		return department;
	}
	public void setDepartment(List<Department> department) {
		this.department = department;
	}
	public DepartmentService getDepartmentService() {
		return departmentService;
	}
	public void setDepartmentService(DepartmentService departmentService) {
		this.departmentService = departmentService;
	}
	public List<PostSet> getPostSet() {
		return postSet;
	}
	public void setPostSet(List<PostSet> postSet) {
		this.postSet = postSet;
	}
	public PostSetService getPostSetService() {
		return postSetService;
	}
	public void setPostSetService(PostSetService postSetService) {
		this.postSetService = postSetService;
	}
	public Dossier getDossier() {
		return dossier;
	}
	public void setDossier(Dossier dossier) {
		this.dossier = dossier;
	}
	public DossierService getDossierService() {
		return dossierService;
	}
	public void setDossierService(DossierService dossierService) {
		this.dossierService = dossierService;
	}
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public PostChange getPostChange() {
		return postChange;
	}
	public void setPostChange(PostChange postChange) {
		this.postChange = postChange;
	}
	public PostChangeService getPostChangeService() {
		return postChangeService;
	}
	public void setPostChangeService(PostChangeService postChangeService) {
		this.postChangeService = postChangeService;
	}
	public Integer getDossierId() {
		return dossierId;
	}
	public void setDossierId(Integer dossierId) {
		this.dossierId = dossierId;
	}
	
	@Action("listPostChange")
	public String listPostChange(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(PostChange.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getPostChangeService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	
	@Action("editPostChange")
	public String editPostChange(){
		this.department=this.getDepartmentService().getAllDepartment();
		this.postSet=this.getPostSetService().getAllPostSet();
		return SUCCESS;
	}
	@Action(value = "savePostChange", results ={ 
			@Result(name = "success", type = "redirect", location = "listPostChange"),
			@Result(name = "error", type = "chain", location = "editPostChange")})
	public String savePostChange(){
//		if(dossier!=null){
//			dossier.setDepartment(postChange.getDepartment());
//			dossier.setPostSet(postChange.getPostSet());
//			this.dossierService.save(dossier);
//		}
//		this.postChangeService.save(postChange);
		this.getPostChangeService().savePostChange(postChange, dossier);
		return SUCCESS;
	}
//	@Action(value="ajaxDossierId",results = { @Result(name = "success", type = "json",
//			params = {"root", "dossier" }) })
//	public String ajaxDossierId(){
//		this.dossier=this.getDossierService().getDossierById(dossierId);
//		return SUCCESS;
//	}
	@Action(value = "removePostChange", results ={ 
			@Result(name = "success", type = "redirect", location = "listPostChange"),
			@Result(name = "error", type = "chain", location = "listPostChange")})
	public String remove(){
		if(ids==null){
			this.addActionError("请选择一行!");
			return ERROR;
		}
		this.getPostChangeService().batchRemove(ids);
		return SUCCESS;
	}
}
